package com.oxygen.fastfile.core.strategy;

import com.oxygen.fastfile.core.FileStorageHelpService;
import com.oxygen.fastfile.core.config.FileStorageConfig;
import com.oxygen.fastfile.core.util.ClassUtil;

/**
 * @author wangjie
 * @version V1.0
 * @title: AbstractFileStorageStrategy
 * @package: com.oxygen.fastfile.core.strategy
 * @description: TODO
 * @date 2022/3/26 22:03
 **/
public abstract class AbstractFileStorageStrategy implements FileStorageStrategy {

    protected FileStorageHelpService fileStorageHelpService;

    public void setFileStorageHelpService(FileStorageHelpService fileStorageHelpService) {
        this.fileStorageHelpService = fileStorageHelpService;
    }

    protected void checkFileStorageConfig(FileStorageConfig sourceConfig, Class<?> targetConfigClazz) throws Exception {
        if (sourceConfig == null) {
            throw new RuntimeException("FileStorageConfig is required.");
        }
        if (!ClassUtil.isAssignable(sourceConfig.getClass(), targetConfigClazz)) {
            throw new RuntimeException("Unsupported parameter type, please use " + ClassUtil.getClassName(targetConfigClazz, true) + ", a subclass of FileStorageConfig");
        }
    }
}
